package com.iwunu.gateway.service.impl;

import javax.annotation.Resource;

import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import com.iwunu.gateway.entity.FLockLog;
import com.iwunu.gateway.service.FacesLogMongodbService;

@Component
public class FacesLogMongodbServiceImpl implements FacesLogMongodbService {
	 @Resource
	 private MongoTemplate mongoTemplate;
	public FLockLog getFacesLog(String clientId,Integer type) {
		Query query = new Query(Criteria.where("flDeviceId").is(clientId).and("type").is(type).and("status").is(-1));
		FLockLog fLockLog = mongoTemplate.findOne(query, FLockLog.class);
       return fLockLog;
	  }

	@Override
	public void save(FLockLog flog) {
		Query query = new Query(Criteria.where("clientId").is(flog.getClientId()).and("type").is(flog.getType()).and("status").is(-1));
		Update update = Update.update("isSucc",true).set("status", 0);
		mongoTemplate.updateMulti(query, update, "FLockLog");
	}

}
